package com.hrpmar.service.impl;

import com.hrpmar.controller.dto.MedicperDto;
import com.hrpmar.mapper.*;
import com.hrpmar.pojo.*;
import com.hrpmar.service.MedicperService;
import com.hrpmar.utils.Pager;
import com.hrpmar.utils.genNumUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 李松松 on 2017/11/15.
 */
@Service
@Transactional
public class MedicperServiceImpl implements MedicperService {


    @Resource
    private DepartmentMapper departmentMapper;

    @Resource
    private MedicperMapper medicperMapper;

    @Resource
    private RoleMapper roleMapper;

    @Resource
    private DivisionMapper divisionMapper;

    @Resource
    private WorkerMapper workerMapper;


    //医护人员分页查询  (部门分类)
    @Override
    public Pager searchByMedicperByWhere(MedicperDto dto, Integer offset, Integer limit) {
        //获取部门信息
        Department dep = departmentMapper.searchDepByRoleId(dto.getRoleId());
        dto.setDep(dep);
        Pager pager = new Pager();
        pager.setRows(medicperMapper.searchByMedicperByWhere(dto,offset,limit));
        pager.setTotal(medicperMapper.total(dto));
        return pager;
    }

    @Override
    public List<Role> getRoleByWoJubnum(Integer wo_jubnum) {
        return roleMapper.getRoleByWoJubnum(wo_jubnum);
    }

    @Override
    public List<Division> getDivision() {
        return divisionMapper.searchDivision();
    }

    @Override
    public Worker searchDisplayInfo(String woJubnum) {
        return workerMapper.searchDisplayInfo(woJubnum);
    }

    @Override
    public Integer addWorkerAndMedicperAspect(Worker worker, Medicper medicper) {
            workerMapper.addWorker(worker);
           Integer i = medicperMapper.addMedicper(medicper);
        return i;
    }

    @Override
    public String searchDescWorker() {
        return genNumUtil.getNum(workerMapper.searchDescWorkerNum());
    }

    /**
     * 根据角色查询部门
     * @param roleId
     * @return
     */
    @Override
    public Department searchByroleId(Integer roleId) {
        return departmentMapper.searchDepByRoleId(roleId);
    }

    /**
     * 根据员工编号查询科室
     * @param woJubnum
     * @return
     */
    @Override
    public Division searchDivisionBywoJubnum(String woJubnum) {
        return divisionMapper.searchDivisionBywoJubnum(woJubnum);
    }
    //删除
    @Override
    public Integer delWorkerAndMedicper(String[] woIds, String[] perIds) {
        medicperMapper.delMedicper(perIds);
        Integer i = workerMapper.delWorker(woIds);
        return i;
    }
    //查询上一个
    @Override
    public Worker topWorkerOne(MedicperDto dto,Integer perId) {
        return workerMapper.topWorkerOne(dto,perId);
    }
    //查询下一个
    @Override
    public Worker NextWorkerOne(MedicperDto dto, Integer perId) {
        return workerMapper.NextWorkerOne(dto,perId);
    }

    @Override
    public Role getRoleByroleId(Integer roleId) {
        return roleMapper.getRoleByRoleId(roleId);
    }
    //上一个(获取编号)
    @Override
    public Medicper searchTopPerId(MedicperDto dto,Integer perId) {
        return medicperMapper.searchTopPerId(dto,perId);
    }
    //下一个(获取编号)
    @Override
    public Medicper searchNextPerId(MedicperDto dto,Integer perId) {
        return medicperMapper.searchNextPerId(dto,perId);
    }

    @Override
    public Medicper searchmedicperX(String woJubnum) {
        return workerMapper.searchmedicperX(woJubnum);
    }

    @Override
    public Integer updateMedicperAspect(Medicper medicper, Worker worker) {
        workerMapper.updateWorker(worker);
        Integer i = medicperMapper.updateMedicper(medicper);
        return i;
    }
}
